This markdown will be utilized for data cleaning and diagnostic checks
In the cannon task, participants are instructed to place a shield at any point around a circle (Nassar et al., 2019). This shield covers only a portion of the 360-degree circle. The goal of the task is to infer where a cannonball might hit along the circle based on the information gathered from previous cannonball strikes and place the shield at those locations. Before each block of the task, the generative structure of the block is fully explained to the participants via written instructions and practice trials of the task. During the practice trials, participants can see where the cannon is aimed and use that information to place their shield. The cannon could theoretically hit anywhere within a 10-degree range from the center of the cannon’s muzzle. After this practice phase, participants complete the primary experiment where the cannon is removed and they must infer the cannon’s aim. The pattern of the cannon’s aim can either (1) change slightly within a specified range of the circle, with “oddball” cannonball shots striking about 14 percent of the time anywhere along the circle, or (2) remain stationary on most trials, and re-position to a random angle on approximately 14 percent of trials and remain stationary at this new angle. Participants receive explicit instructions regarding the nature of each of these blocks following the instructional phase, meaning they know whether the upcoming block will be from an oddball or change-point distribution. Participants complete 240 experimental trials in each condition, divided into 60-trial blocks, for a total of 480 trials. On each trial, participants adjust the position of their shield and lock in their decision. After their choice has been made, there is a 500ms delay before the location of the cannonball is revealed for 500ms. This provides an explicit representation of how far away the center of the shield fell from the cannonball’s strike, providing visual feedback about their PE from the cannonball’s actual location (Figure 2a, ii). After participants are shown how far off they were, the outcome of the task is revealed (Figure 2a, iii). After another brief delay (1000ms), the size of the participant’s shield is revealed alongside the cannonball, showing whether they successfully blocked the projectile. While the shield is always centered on the participant’s chosen location, it varies in size such that participants are never totally certain they will block the cannonball. Thus, minimizing the PE in the feedback phase is the optimal strategy for performing well in the task. At the end of a block, participants are provided feedback in terms of how many cannonballs they caught as a percentage of the total cannonballs.
This dataframe resulting from this cleaning is an example dataset. Because the cleaning code will be updated, the current cleaning code does not need to be reviewed unless you suspect anaomalies in the resulting dataframe. For any questions related to the definition of task variables, please refer to: https://docs.google.com/spreadsheets/d/1V2UD28C_zAfH90BnNO3si6c0-qDUDFbHoU44rfdEt4I/edit#gid=1309555968. Skip to heading Pilot Results for information on pilot data.
It should also be noted that data for this pilot came from two, slightly different versions of the ADLT. The first version failed to record trial latency. Thus, latencies were only examined for a subset of participants.
####Setup - Choose options
print_plots <- "cp" # could be "random"
get_model_params <- TRUE
pilot <- FALSE
#load data
if (pilot == FALSE){
cannon_data_raw <- data.table::fread("~/github_repos/Cannon_Task_Inquisit/Data/PUBS_Batch1_C_Samp.csv", fill = TRUE) %>%
dplyr::filter(subject != 1) %>%
dplyr::filter(subject != "subject")
} else{
cannon_data_raw <- data.table::fread("~/github_repos/Cannon_Task_Inquisit/Data/PUBS_Batch1_C_Samp.csv", fill = TRUE) %>%
dplyr::filter(subject == 1) %>%
dplyr::filter(subject != "subject")
}
#FILTER OUT TIMES BEFORE OFFICIAL DATA COLLECTION
load("cannon_processing.Rdata")
#load("Cannonball_Pilot_Cleaned_Data.Rdata")
iq_names <- colnames(cannon_data_raw)
# #If it's a pilot without numbers, do this
# if (length(unique(cannon_data_raw$subject == 1))){
# cannon_data_raw <- cannon_data_raw %>% group_by(time) %>% mutate(subject= cur_group_id())
# unique(cannon_data_raw$subject)
# }
It is important to get rid of excess trials and only retain information that will be important in analysis.
if (length(Raw) == length(Chopped)){
print("Data Successfully Chopped")
} else {
print("Data Not Chopped")
}
## [1] "Data Successfully Chopped"
This chunk sets new variables and alters any old ones that need to be tidied. The variables created by the set_vars vector are:
predErr. Absolute prediction error (calculated using the discrep function): the PE from outcome to shield placement distMean. Prediction error from mean of distribution to shield placement. Calculated with discrep function. catch_miss. Codes values as factors “catch”, “miss”, “noresp”. Used for coding and mean comparison changepoint A column that reflects the trial number of changepoints. contains trial number when changepoint occurs and NA when no changepoint has occured.
Table 1. High-Level Task Performance. This check returns block-level info about subject’s performance. Participants are flagged if they did not respond to more than half of trials.
set_vars <- c("predErr", "distMean", "catch_miss", "changepoint", "perf", "total_trialnum" ) ##name variables needed for analysis, add as they become apparent
trim_cols <- TRUE
cannon_data <- create_vars(cannon_data, set_vars) ## Intialize rows to calculate
cannon_data <- cannon_data %>% ungroup() %>% group_by(subject) %>% mutate(cBal = ifelse(cond[1] == "CHANGEPOINT", 2, 1))
if (trim_cols == TRUE){
if (cannon_data$percentTrialsStay == .86){
drop <- c("percentTrialsStay","blockcode","trialcode",
"block.InstructionBlock.timestamp","trial.begin_block.timestamp",
"trial.mainloop.timestamp","trial.placeshield_mouse.timestamp","trial.showPE.timestamp"
,"trial.cannon_outcome.timestamp","picture.shield.currentitem")
}
drop <- c("blockcode","trialcode",
"block.InstructionBlock.timestamp","trial.begin_block.timestamp",
"trial.mainloop.timestamp","trial.placeshield_mouse.timestamp"
, "trial.showPE.timestamp"
,"trial.cannon_outcome.timestamp","picture.shield.currentitem")
cannon_data <- cannon_data[,!(names(cannon_data) %in% drop)]
}
cleaned_names <- colnames(cannon_data)
save(model_names, iq_names, cleaned_names, file = "cannon_processing.Rdata")
It’s probably worth writing this into a function as well. I should probably do this before I implement high-level checks. Ideas for things I might need to check are: Miscodes. Misses that are actually hits, Hits that are actually misses, etc. Odd numbers of trials Participants bailing early on the task, getting stuck somewhere, etc.
In this pilot data, we are still getting occasional hits and misses that don’t make sense. I think this is due to
cannon_data <- check_irreg(cannon_data) #check for any mistaken hits
irreg_plot_hit <- cannon_data %>% filter(grepl("CHECK_HIT", Irreg)) %>% select(subject, cond, blocknum, trialnum, catch_miss, angmu, placementAngle, outcome, predErr, angleup, angledown, shield_size)
irreg_plot_miss <- cannon_data %>% filter(grepl("CHECK_MISS", Irreg)) %>% select(subject, cond, blocknum, trialnum, catch_miss, angmu, placementAngle, outcome, predErr, angleup, angledown, shield_size)
irreg_plot_NA <- cannon_data %>% filter(grepl("CHECK_NA", Irreg)) %>% select(subject, cond, blocknum, trialnum, catch_miss, angmu, placementAngle, outcome, predErr, angleup, angledown, shield_size)
range <- cannon_data %>%
group_by(subject, time) %>% summarise(placement_angle_min = min(cannon_data$placementAngle %>% na.omit),
placement_angle_max = max(cannon_data$placementAngle %>% na.omit),
outcome_min = min(cannon_data$outcome %>% na.omit),
outcome_max = max(cannon_data$outcome %>% na.omit),
angleup_min = min(cannon_data$angleup %>% na.omit),
angleup_max = max(cannon_data$angleup %>% na.omit),
angledown_min = min(cannon_data$angledown %>% na.omit),
angledown_max = max(cannon_data$angledown %>% na.omit))
if(nrow(irreg_plot_hit) > 0){
irreg_plot_hit
}
if(nrow(irreg_plot_miss) > 0){
irreg_plot_miss
}
## # A tibble: 37 × 12
## # Groups: subject [12]
## subject cond blocknum trialnum catch_miss angmu placementAngle outcome
## <dbl> <fct> <dbl> <dbl> <chr> <dbl> <dbl> <dbl>
## 1 402292 CHANGEPOINT 2 36 miss 297. 306. 303.
## 2 402292 CHANGEPOINT 4 11 miss 174. 192. 197.
## 3 402292 ODDBALL 2 59 miss 173. 177. 183.
## 4 811078 CHANGEPOINT 2 7 miss 206. 217. 216.
## 5 811078 CHANGEPOINT 3 31 miss 234. 221. 215.
## 6 811078 CHANGEPOINT 3 55 miss 305. 305. 312.
## 7 811078 CHANGEPOINT 3 58 miss 305. 326. 318.
## 8 811078 ODDBALL 2 43 miss 47.0 15.9 16.2
## 9 811078 ODDBALL 3 23 miss 217. 231. 237.
## 10 858150 ODDBALL 4 40 miss 255. 242. 236.
## # … with 27 more rows, and 4 more variables: predErr <dbl>, angleup <dbl>,
## # angledown <dbl>, shield_size <dbl>
if(nrow(irreg_plot_NA) > 0){
irreg_plot_NA
}
obj <- cannon_data %>% group_by(subject, cond, blocknum, totalearnings) %>%
summarise(obscount = n(), avg_PE = mean(predErr, na.rm = TRUE),
dist_mean = mean(distMean,na.rm = TRUE),
percent_caught = max(cannonballs_caught/max(trialnum)),
percent_noresp = (sum(outcomeindex == 1)/max(trialnum)),
num_changepoints = sum(!is.na(changepoint))) %>%
arrange(subject,totalearnings) %>% group_by(subject) %>% mutate(taskearnings = max(totalearnings)) %>% mutate(Avg_overall_PE = mean(avg_PE, na.rm = TRUE)) %>% ungroup()
#save(obj, cannon_data, file = "Cannonball_Pilot_Example_Perfect_Data.Rdata")
colormatrix <- ifelse(obj$percent_noresp >= .2 || obj$obscount != 60, wes_palette("Cavalcanti1")[c(1)], "white") ##potentially save these as bad_blocks vector
bad_blocks <- obj %>% dplyr::filter( percent_noresp >= .2)
tab <- obj %>% flextable() %>% flextable::bg(j = 1:ncol(obj), bg=colormatrix)
cannon_earnings <- cannon_data %>% group_by(subject) %>% summarize(cents_earned = max(totalearnings)) %>% dplyr::rename(centsearned_c = cents_earned)
save(cannon_earnings, file = "~/github_repos/PUBS_Data_Verification/Payment/Cannon.Rdata")
tab
subject | cond | blocknum | totalearnings | obscount | avg_PE | dist_mean | percent_caught | percent_noresp | num_changepoints | taskearnings | Avg_overall_PE |
224,761 | ODDBALL | 1 | 3.5 | 60 | 41.62901 | 27.076921 | 0.3166667 | 0.00000000 | 9 | 81.5 | 35.42595 |
224,761 | ODDBALL | 2 | 13.0 | 60 | 30.22872 | 20.765068 | 0.4000000 | 0.00000000 | 5 | 81.5 | 35.42595 |
224,761 | ODDBALL | 3 | 25.0 | 60 | 30.42085 | 18.076543 | 0.4000000 | 0.00000000 | 8 | 81.5 | 35.42595 |
224,761 | ODDBALL | 4 | 37.0 | 61 | 51.45813 | 33.149300 | 0.3333333 | 0.01666667 | 15 | 81.5 | 35.42595 |
224,761 | CHANGEPOINT | 1 | 48.5 | 60 | 25.41116 | 19.089178 | 0.3333333 | 0.00000000 | 5 | 81.5 | 35.42595 |
224,761 | CHANGEPOINT | 2 | 58.5 | 60 | 29.45198 | 23.080525 | 0.3833333 | 0.00000000 | 7 | 81.5 | 35.42595 |
224,761 | CHANGEPOINT | 3 | 70.0 | 60 | 43.49430 | 40.880106 | 0.3833333 | 0.00000000 | 12 | 81.5 | 35.42595 |
224,761 | CHANGEPOINT | 4 | 81.5 | 60 | 31.31343 | 24.928210 | 0.4000000 | 0.01666667 | 7 | 81.5 | 35.42595 |
271,259 | ODDBALL | 1 | 5.0 | 61 | 49.55716 | 34.417935 | 0.2000000 | 0.01666667 | 9 | 71.5 | 39.14499 |
271,259 | ODDBALL | 2 | 11.0 | 60 | 41.80097 | 24.625574 | 0.1666667 | 0.00000000 | 5 | 71.5 | 39.14499 |
271,259 | ODDBALL | 3 | 16.0 | 60 | 33.57594 | 17.789174 | 0.4000000 | 0.00000000 | 8 | 71.5 | 39.14499 |
271,259 | ODDBALL | 4 | 28.0 | 60 | 34.39296 | 20.190864 | 0.3333333 | 0.00000000 | 11 | 71.5 | 39.14499 |
271,259 | CHANGEPOINT | 1 | 41.5 | 60 | 44.77484 | 36.921658 | 0.2500000 | 0.00000000 | 8 | 71.5 | 39.14499 |
271,259 | CHANGEPOINT | 2 | 49.0 | 60 | 33.84849 | 27.806211 | 0.3833333 | 0.00000000 | 10 | 71.5 | 39.14499 |
271,259 | CHANGEPOINT | 3 | 60.5 | 60 | 36.71150 | 30.867425 | 0.3666667 | 0.00000000 | 8 | 71.5 | 39.14499 |
271,259 | CHANGEPOINT | 4 | 71.5 | 60 | 38.49810 | 28.729403 | 0.2833333 | 0.00000000 | 8 | 71.5 | 39.14499 |
336,228 | CHANGEPOINT | 1 | 6.5 | 60 | 30.54440 | 27.294662 | 0.3666667 | 0.00000000 | 6 | 68.0 | 42.65202 |
336,228 | CHANGEPOINT | 2 | 17.5 | 61 | 47.54205 | 43.676859 | 0.2000000 | 0.01666667 | 12 | 68.0 | 42.65202 |
336,228 | CHANGEPOINT | 3 | 23.5 | 63 | 46.72723 | 37.243623 | 0.2666667 | 0.05000000 | 7 | 68.0 | 42.65202 |
336,228 | CHANGEPOINT | 4 | 31.5 | 60 | 42.74205 | 39.347967 | 0.2666667 | 0.01666667 | 10 | 68.0 | 42.65202 |
336,228 | ODDBALL | 1 | 42.5 | 63 | 37.14646 | 28.253372 | 0.4000000 | 0.05000000 | 5 | 68.0 | 42.65202 |
336,228 | ODDBALL | 2 | 54.5 | 60 | 40.32044 | 25.408142 | 0.2666667 | 0.00000000 | 10 | 68.0 | 42.65202 |
336,228 | ODDBALL | 3 | 62.5 | 61 | 50.65509 | 33.119903 | 0.1833333 | 0.01666667 | 9 | 68.0 | 42.65202 |
336,228 | ODDBALL | 4 | 68.0 | 60 | 45.53843 | 34.392121 | 0.3000000 | 0.00000000 | 8 | 68.0 | 42.65202 |
377,598 | CHANGEPOINT | 1 | 3.0 | 60 | 32.85380 | 28.488223 | 0.4166667 | 0.00000000 | 10 | 80.5 | 38.17436 |
377,598 | CHANGEPOINT | 2 | 15.5 | 61 | 26.25010 | 15.014226 | 0.4333333 | 0.01666667 | 5 | 80.5 | 38.17436 |
377,598 | CHANGEPOINT | 3 | 28.5 | 61 | 44.85141 | 39.808276 | 0.2666667 | 0.01666667 | 12 | 80.5 | 38.17436 |
377,598 | CHANGEPOINT | 4 | 36.5 | 60 | 30.24160 | 23.782126 | 0.4000000 | 0.00000000 | 3 | 80.5 | 38.17436 |
377,598 | ODDBALL | 1 | 51.0 | 60 | 53.25499 | 29.383478 | 0.2666667 | 0.00000000 | 14 | 80.5 | 38.17436 |
377,598 | ODDBALL | 2 | 59.0 | 60 | 41.37957 | 24.893768 | 0.2666667 | 0.00000000 | 9 | 80.5 | 38.17436 |
377,598 | ODDBALL | 3 | 67.0 | 60 | 32.69497 | 23.976664 | 0.4500000 | 0.00000000 | 8 | 80.5 | 38.17436 |
377,598 | ODDBALL | 4 | 80.5 | 60 | 43.86846 | 30.226365 | 0.3666667 | 0.00000000 | 9 | 80.5 | 38.17436 |
402,292 | CHANGEPOINT | 1 | 5.0 | 64 | 28.92509 | 22.896893 | 0.4166667 | 0.08333333 | 8 | 95.5 | 33.65004 |
402,292 | CHANGEPOINT | 2 | 17.5 | 60 | 26.24258 | 23.627409 | 0.5333333 | 0.00000000 | 8 | 95.5 | 33.65004 |
402,292 | CHANGEPOINT | 3 | 33.5 | 60 | 42.76464 | 35.226504 | 0.3833333 | 0.00000000 | 11 | 95.5 | 33.65004 |
402,292 | CHANGEPOINT | 4 | 45.0 | 60 | 27.83720 | 22.541303 | 0.3666667 | 0.00000000 | 5 | 95.5 | 33.65004 |
402,292 | ODDBALL | 1 | 60.0 | 61 | 40.90058 | 17.816957 | 0.4500000 | 0.01666667 | 12 | 95.5 | 33.65004 |
402,292 | ODDBALL | 2 | 73.5 | 60 | 30.32393 | 14.884482 | 0.3666667 | 0.00000000 | 9 | 95.5 | 33.65004 |
402,292 | ODDBALL | 3 | 84.5 | 60 | 34.07171 | 16.411268 | 0.3666667 | 0.00000000 | 7 | 95.5 | 33.65004 |
402,292 | ODDBALL | 4 | 95.5 | 63 | 38.13463 | 27.905186 | 0.4000000 | 0.06666667 | 10 | 95.5 | 33.65004 |
577,910 | CHANGEPOINT | 1 | 5.5 | 60 | 30.36348 | 27.050561 | 0.2833333 | 0.00000000 | 9 | 87.0 | 32.85146 |
577,910 | CHANGEPOINT | 2 | 14.0 | 60 | 32.74690 | 28.708105 | 0.3500000 | 0.00000000 | 9 | 87.0 | 32.85146 |
577,910 | CHANGEPOINT | 3 | 24.5 | 60 | 36.87167 | 35.643075 | 0.3000000 | 0.00000000 | 8 | 87.0 | 32.85146 |
577,910 | CHANGEPOINT | 4 | 33.5 | 60 | 25.71217 | 22.170260 | 0.4833333 | 0.00000000 | 5 | 87.0 | 32.85146 |
577,910 | ODDBALL | 1 | 50.5 | 60 | 44.22407 | 16.177009 | 0.3333333 | 0.00000000 | 12 | 87.0 | 32.85146 |
577,910 | ODDBALL | 2 | 60.5 | 60 | 31.72914 | 16.849873 | 0.4166667 | 0.00000000 | 7 | 87.0 | 32.85146 |
577,910 | ODDBALL | 3 | 73.0 | 60 | 29.79863 | 16.863515 | 0.4666667 | 0.00000000 | 9 | 87.0 | 32.85146 |
577,910 | ODDBALL | 4 | 87.0 | 60 | 31.36564 | 15.276319 | 0.4666667 | 0.00000000 | 8 | 87.0 | 32.85146 |
628,645 | ODDBALL | 1 | 5.5 | 60 | 26.56184 | 13.116165 | 0.4333333 | 0.00000000 | 8 | 96.0 | 32.37228 |
628,645 | ODDBALL | 2 | 18.5 | 60 | 27.91205 | 10.883989 | 0.5166667 | 0.00000000 | 8 | 96.0 | 32.37228 |
628,645 | ODDBALL | 3 | 34.0 | 60 | 38.90905 | 20.060098 | 0.3500000 | 0.00000000 | 10 | 96.0 | 32.37228 |
628,645 | ODDBALL | 4 | 44.5 | 60 | 31.25128 | 16.253557 | 0.3333333 | 0.00000000 | 7 | 96.0 | 32.37228 |
628,645 | CHANGEPOINT | 1 | 58.5 | 60 | 35.33134 | 29.426295 | 0.3166667 | 0.00000000 | 9 | 96.0 | 32.37228 |
628,645 | CHANGEPOINT | 2 | 68.0 | 60 | 43.10559 | 37.549791 | 0.3500000 | 0.00000000 | 12 | 96.0 | 32.37228 |
628,645 | CHANGEPOINT | 3 | 78.5 | 60 | 23.13003 | 18.605017 | 0.5833333 | 0.00000000 | 4 | 96.0 | 32.37228 |
628,645 | CHANGEPOINT | 4 | 96.0 | 60 | 32.77704 | 25.674881 | 0.3333333 | 0.00000000 | 10 | 96.0 | 32.37228 |
668,126 | CHANGEPOINT | 1 | 2.0 | 60 | 36.95324 | 31.952252 | 0.2833333 | 0.00000000 | 9 | 87.5 | 32.80759 |
668,126 | CHANGEPOINT | 2 | 10.5 | 60 | 21.13118 | 16.614121 | 0.5500000 | 0.00000000 | 8 | 87.5 | 32.80759 |
668,126 | CHANGEPOINT | 3 | 27.0 | 60 | 34.17694 | 29.179895 | 0.3666667 | 0.00000000 | 7 | 87.5 | 32.80759 |
668,126 | CHANGEPOINT | 4 | 38.0 | 60 | 35.30670 | 30.293997 | 0.3500000 | 0.00000000 | 10 | 87.5 | 32.80759 |
668,126 | ODDBALL | 1 | 52.0 | 60 | 38.47694 | 21.303383 | 0.3666667 | 0.00000000 | 9 | 87.5 | 32.80759 |
668,126 | ODDBALL | 2 | 63.0 | 60 | 29.38810 | 10.107484 | 0.4333333 | 0.00000000 | 8 | 87.5 | 32.80759 |
668,126 | ODDBALL | 3 | 76.0 | 60 | 36.90380 | 11.268781 | 0.3833333 | 0.00000000 | 10 | 87.5 | 32.80759 |
668,126 | ODDBALL | 4 | 87.5 | 60 | 30.12381 | 17.375251 | 0.4333333 | 0.00000000 | 8 | 87.5 | 32.80759 |
673,855 | ODDBALL | 1 | 5.0 | 60 | 33.67543 | 20.589696 | 0.3500000 | 0.00000000 | 6 | 93.0 | 33.21493 |
673,855 | ODDBALL | 2 | 15.5 | 60 | 49.21330 | 32.052403 | 0.2666667 | 0.00000000 | 11 | 93.0 | 33.21493 |
673,855 | ODDBALL | 3 | 23.5 | 60 | 35.03939 | 14.182960 | 0.4166667 | 0.00000000 | 9 | 93.0 | 33.21493 |
673,855 | ODDBALL | 4 | 36.0 | 60 | 26.75490 | 10.584459 | 0.5166667 | 0.00000000 | 9 | 93.0 | 33.21493 |
673,855 | CHANGEPOINT | 1 | 54.0 | 60 | 36.44818 | 31.163798 | 0.4333333 | 0.00000000 | 9 | 93.0 | 33.21493 |
673,855 | CHANGEPOINT | 2 | 67.0 | 60 | 23.87879 | 16.272804 | 0.3666667 | 0.00000000 | 6 | 93.0 | 33.21493 |
673,855 | CHANGEPOINT | 3 | 78.0 | 60 | 24.26752 | 20.737474 | 0.5000000 | 0.00000000 | 7 | 93.0 | 33.21493 |
673,855 | CHANGEPOINT | 4 | 93.0 | 60 | 36.44195 | 36.375458 | 0.3833333 | 0.00000000 | 10 | 93.0 | 33.21493 |
710,889 | CHANGEPOINT | 1 | 5.5 | 60 | 34.80085 | 33.063139 | 0.3833333 | 0.00000000 | 6 | 83.0 | 38.06267 |
710,889 | CHANGEPOINT | 2 | 17.0 | 60 | 38.68461 | 34.718666 | 0.3166667 | 0.00000000 | 11 | 83.0 | 38.06267 |
710,889 | CHANGEPOINT | 3 | 26.5 | 60 | 41.29317 | 37.931099 | 0.3333333 | 0.00000000 | 9 | 83.0 | 38.06267 |
710,889 | CHANGEPOINT | 4 | 36.5 | 61 | 35.67378 | 28.989034 | 0.3500000 | 0.01666667 | 6 | 83.0 | 38.06267 |
710,889 | ODDBALL | 1 | 48.0 | 60 | 52.18990 | 35.724757 | 0.3166667 | 0.00000000 | 12 | 83.0 | 38.06267 |
710,889 | ODDBALL | 2 | 57.5 | 60 | 27.57573 | 26.077728 | 0.4666667 | 0.00000000 | 6 | 83.0 | 38.06267 |
710,889 | ODDBALL | 3 | 71.5 | 60 | 34.40736 | 16.942531 | 0.3833333 | 0.01666667 | 11 | 83.0 | 38.06267 |
710,889 | ODDBALL | 4 | 83.0 | 61 | 39.87600 | 19.312735 | 0.3000000 | 0.01666667 | 8 | 83.0 | 38.06267 |
744,735 | CHANGEPOINT | 1 | 5.5 | 60 | 60.07702 | 53.770315 | 0.1166667 | 0.00000000 | 9 | 81.0 | 41.67317 |
744,735 | CHANGEPOINT | 2 | 9.0 | 60 | 31.10472 | 25.802955 | 0.4666667 | 0.00000000 | 6 | 81.0 | 41.67317 |
744,735 | CHANGEPOINT | 3 | 23.0 | 60 | 33.37430 | 29.996762 | 0.4166667 | 0.00000000 | 7 | 81.0 | 41.67317 |
744,735 | CHANGEPOINT | 4 | 35.5 | 60 | 40.79518 | 40.458034 | 0.3333333 | 0.00000000 | 10 | 81.0 | 41.67317 |
744,735 | ODDBALL | 1 | 48.0 | 60 | 45.09576 | 31.416162 | 0.3500000 | 0.00000000 | 10 | 81.0 | 41.67317 |
744,735 | ODDBALL | 2 | 58.5 | 61 | 53.54923 | 42.514184 | 0.2500000 | 0.01666667 | 10 | 81.0 | 41.67317 |
744,735 | ODDBALL | 3 | 66.0 | 60 | 24.33506 | 16.226587 | 0.5000000 | 0.00000000 | 4 | 81.0 | 41.67317 |
744,735 | ODDBALL | 4 | 81.0 | 60 | 45.05413 | 32.149958 | 0.2833333 | 0.00000000 | 11 | 81.0 | 41.67317 |
808,746 | ODDBALL | 1 | 6.0 | 60 | 28.29567 | 10.636873 | 0.4166667 | 0.00000000 | 10 | 95.0 | 30.20560 |
808,746 | ODDBALL | 2 | 18.5 | 61 | 34.11927 | 18.045936 | 0.3666667 | 0.01666667 | 8 | 95.0 | 30.20560 |
808,746 | ODDBALL | 3 | 29.5 | 61 | 33.82978 | 17.928489 | 0.3500000 | 0.01666667 | 7 | 95.0 | 30.20560 |
808,746 | ODDBALL | 4 | 40.0 | 60 | 25.99732 | 8.621747 | 0.5333333 | 0.00000000 | 10 | 95.0 | 30.20560 |
808,746 | CHANGEPOINT | 1 | 60.0 | 60 | 38.00824 | 30.758833 | 0.3000000 | 0.00000000 | 11 | 95.0 | 30.20560 |
808,746 | CHANGEPOINT | 2 | 69.0 | 60 | 25.53331 | 21.031203 | 0.4833333 | 0.00000000 | 5 | 95.0 | 30.20560 |
808,746 | CHANGEPOINT | 3 | 83.5 | 60 | 27.91244 | 18.573551 | 0.3833333 | 0.00000000 | 7 | 95.0 | 30.20560 |
808,746 | CHANGEPOINT | 4 | 95.0 | 60 | 27.94873 | 25.006262 | 0.4166667 | 0.00000000 | 10 | 95.0 | 30.20560 |
811,078 | CHANGEPOINT | 1 | 6.0 | 60 | 32.82526 | 24.297260 | 0.3833333 | 0.00000000 | 10 | 102.0 | 30.25454 |
811,078 | CHANGEPOINT | 2 | 17.5 | 60 | 27.00323 | 26.085043 | 0.5166667 | 0.00000000 | 7 | 102.0 | 30.25454 |
811,078 | CHANGEPOINT | 3 | 33.0 | 60 | 34.97350 | 29.783597 | 0.3333333 | 0.00000000 | 9 | 102.0 | 30.25454 |
811,078 | CHANGEPOINT | 4 | 43.0 | 60 | 33.24412 | 23.742484 | 0.4500000 | 0.00000000 | 7 | 102.0 | 30.25454 |
811,078 | ODDBALL | 1 | 59.5 | 60 | 25.08809 | 11.484615 | 0.4833333 | 0.00000000 | 12 | 102.0 | 30.25454 |
811,078 | ODDBALL | 2 | 74.0 | 60 | 28.05945 | 18.093290 | 0.5000000 | 0.00000000 | 6 | 102.0 | 30.25454 |
811,078 | ODDBALL | 3 | 89.0 | 60 | 29.48277 | 14.230079 | 0.4333333 | 0.00000000 | 6 | 102.0 | 30.25454 |
811,078 | ODDBALL | 4 | 102.0 | 60 | 31.35989 | 14.092323 | 0.3500000 | 0.00000000 | 11 | 102.0 | 30.25454 |
857,452 | CHANGEPOINT | 1 | 5.5 | 60 | 36.65123 | 28.242767 | 0.2833333 | 0.00000000 | 8 | 45.5 | 40.46407 |
857,452 | CHANGEPOINT | 2 | 14.0 | 61 | 36.43350 | 33.254975 | 0.3833333 | 0.01666667 | 9 | 45.5 | 40.46407 |
857,452 | CHANGEPOINT | 3 | 25.5 | 60 | 34.70404 | 27.901381 | 0.3333333 | 0.00000000 | 7 | 45.5 | 40.46407 |
857,452 | CHANGEPOINT | 4 | 35.5 | 63 | 48.96288 | 43.032025 | 0.2166667 | 0.06666667 | 11 | 45.5 | 40.46407 |
857,452 | ODDBALL | 1 | 45.5 | 8 | 45.56869 | 33.305336 | 0.0000000 | 0.80000000 | 4 | 45.5 | 40.46407 |
858,150 | CHANGEPOINT | 1 | 2.5 | 60 | 46.35372 | 44.933655 | 0.3000000 | 0.00000000 | 10 | 66.0 | 44.89727 |
858,150 | CHANGEPOINT | 2 | 11.5 | 60 | 57.15375 | 55.822245 | 0.2166667 | 0.00000000 | 10 | 66.0 | 44.89727 |
858,150 | CHANGEPOINT | 3 | 18.0 | 60 | 38.79206 | 38.859210 | 0.3333333 | 0.00000000 | 8 | 66.0 | 44.89727 |
858,150 | CHANGEPOINT | 4 | 28.0 | 60 | 42.09811 | 37.402129 | 0.2833333 | 0.00000000 | 7 | 66.0 | 44.89727 |
858,150 | ODDBALL | 1 | 38.5 | 60 | 58.03082 | 41.179268 | 0.2166667 | 0.00000000 | 9 | 66.0 | 44.89727 |
858,150 | ODDBALL | 2 | 45.0 | 60 | 43.56183 | 37.177499 | 0.2833333 | 0.00000000 | 7 | 66.0 | 44.89727 |
858,150 | ODDBALL | 3 | 53.5 | 60 | 38.68951 | 29.704419 | 0.4166667 | 0.00000000 | 8 | 66.0 | 44.89727 |
858,150 | ODDBALL | 4 | 66.0 | 60 | 34.49836 | 19.766674 | 0.4000000 | 0.00000000 | 10 | 66.0 | 44.89727 |
994,811 | ODDBALL | 1 | 7.0 | 60 | 45.69151 | 25.915430 | 0.2666667 | 0.00000000 | 12 | 83.5 | 36.24162 |
994,811 | ODDBALL | 2 | 15.0 | 61 | 29.91855 | 11.600844 | 0.4500000 | 0.01666667 | 8 | 83.5 | 36.24162 |
994,811 | ODDBALL | 3 | 28.5 | 60 | 26.67216 | 13.211110 | 0.3833333 | 0.00000000 | 6 | 83.5 | 36.24162 |
994,811 | ODDBALL | 4 | 40.0 | 60 | 36.15480 | 19.630240 | 0.3500000 | 0.00000000 | 6 | 83.5 | 36.24162 |
994,811 | CHANGEPOINT | 1 | 52.5 | 60 | 47.02204 | 41.408736 | 0.3666667 | 0.00000000 | 12 | 83.5 | 36.24162 |
994,811 | CHANGEPOINT | 2 | 63.5 | 60 | 33.33062 | 28.863408 | 0.3500000 | 0.00000000 | 7 | 83.5 | 36.24162 |
994,811 | CHANGEPOINT | 3 | 74.0 | 60 | 34.82708 | 30.746041 | 0.3166667 | 0.00000000 | 10 | 83.5 | 36.24162 |
994,811 | CHANGEPOINT | 4 | 83.5 | 60 | 36.31618 | 29.528934 | 0.3833333 | 0.00000000 | 8 | 83.5 | 36.24162 |
Figure 1. Below is a histogram of all reaction time data.This is beautiful!Tried both with and without subject 456, who seems a little problematic based on the summary statistics. Overall, happy with this!
Hist_outliers <- ggplot(cannon_data %>% filter(!subject == 456), aes(x=trial.placeshield_mouse.latency)) + geom_histogram()
Mean_cleaned <- cannon_data %>% filter(!subject == 456) %>% ungroup () %>% filter(!trial.placeshield_mouse.latency == 2500) %>% summarise(mean = mean(trial.placeshield_mouse.latency))
Hist_outliers; Mean_cleaned
## # A tibble: 1 × 1
## mean
## <dbl>
## 1 441.
I’m having some trouble with graphing this. For whatever reason, the oddball graphs are not happy with the tabset format. Everything else seems to be playing nicely, and it seems as though participants are learning across the task.
cowplotcp <- list();cowplotodd <- list()
subjects <- sort(unique(cannon_data$subject))
subjects <- as.character(subjects)
subjects_list <- list(as.character(unique(cannon_data$subject)))
for (i in subjects) {
o <- cannon_data %>% dplyr::filter(subject == i & cond == "ODDBALL") %>% filter(!is.na(predErr))
cowplotodd[[i]] <- local({
i <- i
oddballPE <- ggplot(o, aes(x=trialnum, y=predErr, color = catch_miss)) + geom_point() +
geom_vline(aes(xintercept = changepoint, color = "Oddball")) + scale_color_manual(values = (wes_palette("Cavalcanti1")[c(4,5,2)])) + xlab("Trial Number") + ylab("Response Type") + ggtitle("Raw Prediction Error") + ylab("Size Of Prediction Error") + theme(legend.position = "none") + facet_wrap(~blocknum, ncol = 1)
get_legendo <- ggplot(o, aes(x=trialnum, y=distMean, color = catch_miss)) + geom_point() +
geom_vline(aes(xintercept = changepoint, color = "Oddball")) + scale_color_manual(values = (wes_palette("Cavalcanti1")[c(4,5,2)]))
legendo <- get_legend(get_legendo)
oddballDM <- ggplot(o, aes(x=trialnum, y=distMean, color = catch_miss)) + geom_point() +
geom_vline(aes(xintercept = changepoint, color = "Oddball")) + scale_color_manual(values = (wes_palette("Cavalcanti1")[c(4,5,2)])) + ggtitle ("Distance from Mean") + xlab("Trial Number") + ylab("Size Of Prediction Error") + theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) + theme(legend.position = "none") + facet_wrap(~blocknum, ncol = 1)
i <- cowplot::plot_grid(oddballPE, oddballDM, legendo, ncol = 3, rel_widths = c(2.5,2.1,1))})
}
for (i in subjects){
c <- cannon_data %>% dplyr::filter(subject == i & cond == "CHANGEPOINT") %>% filter(!is.na(predErr))
cowplotcp[[i]] <- local({
i <- i
changepointPE <- ggplot(c,aes(x=trialnum, y=predErr, color = catch_miss)) + geom_point() + geom_vline(aes(xintercept = changepoint, color = "Changepoint")) + scale_color_manual(values = (wes_palette("Cavalcanti1")[c(2,4,5)])) + xlab("Trial Number") + ylab("Response Type") + ggtitle("Raw Prediction Error") + ylab("Size Of Prediction Error") + theme(legend.position = "non7e") + facet_wrap(~blocknum, ncol = 1)
get_legendc <- ggplot(c, aes(x=trialnum, y=distMean, color = catch_miss)) + geom_point() + geom_vline(aes(xintercept = changepoint, color = "Changepoint")) + scale_color_manual(values = (wes_palette("Cavalcanti1")[c(4,5,2)]))
legendc <- get_legend(get_legendc)
#c(5,4,2), 2,5,4, 4,5,2, 2,4,5
changepointDM <- ggplot(c, aes(x=trialnum, y=distMean, color = catch_miss)) + geom_point() +
geom_vline(aes(xintercept = changepoint, color = "Changepoint")) + scale_color_manual(values = (wes_palette("Cavalcanti1")[c(4,5,2)])) + ggtitle ("Distance from Mean") + xlab("Trial Number") + ylab("Size Of Prediction Error") + theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) + theme(legend.position = "none") + facet_wrap(~blocknum, ncol = 1)
i <- cowplot::plot_grid(changepointPE, changepointPE, legendc, ncol = 3, rel_widths = c(2.5,2.1,1))})
}
##print based on the block that came first (use cBal)
#
#
# cowplotall <- list()
# for (i in subjects) {
# cowplotall[[i]] <- local({
# i <- i
# cowplot::plot_grid(cowplotcp[[i]], cowplotodd[[i]], nrow = 2)})
# }
if(print_plots == "cp") {
temp_cp <- c(
"### Subject {{nm}}\n",
"```{r, echo = FALSE}\n",
"cowplotcp[[{{nm}}]] \n",
"```\n",
"\n"
)
plots <- lapply(1:length(cowplotcp), function(nm) {knitr::knit_expand(text = temp_cp)})
} else if (print_plots == "ob"){
template <- c(
"### Subject {{w}}\n",
"```{r, echo = FALSE}\n",
"cowplotodd[[{{w}}]] \n",
"```\n",
"\n"
)
plots <- lapply(1:length(cowplotodd), function(w) {knitr::knit_expand(text = template)})
}
a_1 <- aov(trial.placeshield_mouse.latency ~ cond, data = cannon_data)
summary(a_1)
## Df Sum Sq Mean Sq F value Pr(>F)
## cond 1 1146193 1146193 9.871 0.00169 **
## Residuals 7436 863421730 116114
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 40 observations deleted due to missingness
rt_trialnum <- lm(trial.placeshield_mouse.latency ~ trialnum + cond + blocknum + cBal, data = cannon_data)
summary(rt_trialnum)
##
## Call:
## lm(formula = trial.placeshield_mouse.latency ~ trialnum + cond +
## blocknum + cBal, data = cannon_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -563.13 -213.23 -82.66 115.09 2150.19
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 740.5355 17.8156 41.567 < 2e-16 ***
## trialnum -1.4640 0.2235 -6.552 6.07e-11 ***
## condODDBALL -26.9041 7.7483 -3.472 0.000519 ***
## blocknum -45.2126 3.4623 -13.058 < 2e-16 ***
## cBal -79.6574 7.9500 -10.020 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 333.9 on 7433 degrees of freedom
## (40 observations deleted due to missingness)
## Multiple R-squared: 0.04177, Adjusted R-squared: 0.04125
## F-statistic: 81 on 4 and 7433 DF, p-value: < 2.2e-16
emmeans(rt_trialnum, "cond")
## cond emmean SE df lower.CL upper.CL
## CHANGEPOINT 463 5.48 7433 453 474
## ODDBALL 437 5.62 7433 426 448
##
## Results are averaged over the levels of: cBal
## Confidence level used: 0.95
#emmeans(rt_trialnum, as.character("blocknum"))
#maybe give this an option?
save(cannon_data, file = "~/github_repos/Cannon_Task_Inquisit/Data/cannon_proc.RData")
# if (modeling_ext == TRUE){
# tidy_for_model(cannon_data)
# }